﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
                    xmlns:local="clr-namespace:TfsBacklogMgr.Main"
                    >

    <!--Function to choose appropriate DataTemplate based on tree item's values-->
    <local:SprintWorkItemTemplateSelector x:Key="theSprintDataTemplateSelector"/>
    <local:BacklogtWorkItemTemplateSelector x:Key="theBacklogDataTemplateSelector"/>

    <HierarchicalDataTemplate 
            x:Key="WorkItemTaskTemplate" 
            ItemsSource="{Binding Path=Children}"
            >

        <Border BorderThickness="1" BorderBrush="LightGray" CornerRadius="2" Margin="1">
            <Border.Style>
                <Style>
                    <Setter Property="Border.Background" >
                        <Setter.Value>
                            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                <GradientStop Color="White" Offset="0.0" />
                                <GradientStop Color="#eeeeff" Offset="0.5" />
                                <GradientStop Color="#ccccff" Offset="1.0" />
                            </LinearGradientBrush>
                        </Setter.Value>
                    </Setter>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeViewItem}}}" Value="True">
                            <Setter Property="Border.Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding IsInParentIteration}" Value="False">
                            <Setter Property="Border.Background" Value="#ffffff" />
                            <Setter Property="TextBlock.Foreground" Value="#aaaaaa" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding IsClosed}" Value="True">
                            <Setter Property="TextBlock.Foreground" Value="#aaaaaa" />
                            <Setter Property="Border.Background" >
                                <Setter.Value>
                                    <ImageBrush ImageSource="pack://application:,,,/Pictures/closed-item.png" Stretch="Fill" />
                                </Setter.Value>
                            </Setter>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Border.Style>

            <Grid TextBlock.FontFamily="Corbel" TextBlock.FontSize="10" ShowGridLines="False">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <TextBlock Grid.Row="0" TextWrapping="NoWrap" FontSize="14" FontWeight="800" Padding="2 0" Text="{Binding Title}"/>
                <Image Grid.Row="0" Grid.RowSpan="4" VerticalAlignment="Top" HorizontalAlignment="Right" Source="{Binding AssignedTo.Image}"  Width="32" Height="32" Stretch="UniformToFill" Margin="2 1" />

                <TextBlock Grid.Row="1" TextWrapping="Wrap" Padding="2 0" Text="{Binding Description}">
                        <TextBlock.Style>
                            <Style>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeViewItem}}}" Value="False">
                                        <Setter Property="TextBlock.Visibility" Value="Collapsed" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                </TextBlock>

                <Grid Grid.Row="2">
                    <TextBlock TextWrapping="NoWrap" Padding="2 0" Text="{Binding State}" />
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" >
                        <TextBlock TextWrapping="NoWrap" Padding="2 0" Text="{Binding Hours,StringFormat=\{0\} hours}" Visibility="{Binding Path=HoursVisibility}"/>
                        <TextBlock TextWrapping="NoWrap" Padding="2 0" Text=", " Visibility="{Binding Path=HoursVisibility}"/>
                        <TextBlock TextWrapping="NoWrap" Padding="2 0" Text="{Binding Remain,StringFormat=\{0\} remain}" Visibility="{Binding Path=RemainVisibility}"/>
                    </StackPanel>
                    <Grid.Style>
                        <Style>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeViewItem}}}" Value="True">
                                    <Setter Property="Grid.Visibility" Value="Collapsed" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Grid.Style>
                </Grid>

                <Grid Grid.Row="3">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="2*" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <ComboBox Grid.Column="0" 
                                  ItemsSource="{Binding Path=States}"
                                  Text="{Binding Path=State}">
                    </ComboBox>

                    <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Center"  >
                        <extToolkit:DoubleUpDown Width="40" HorizontalContentAlignment="Right" Text="{Binding Path=Hours}" Minimum="0" FormatString="{Binding Path=HoursFormat}"  Visibility="{Binding Path=HoursVisibility}"/>
                        <TextBlock TextWrapping="NoWrap" Padding="2 0" VerticalAlignment="Center" Text="Hours, " Visibility="{Binding Path=HoursVisibility}" />
                        <extToolkit:DoubleUpDown Width="40" HorizontalContentAlignment="Right" Text="{Binding Path=Remain}" Minimum="0" FormatString="{Binding Path=RemainFormat}" Visibility="{Binding Path=RemainVisibility}"/>
                        <TextBlock TextWrapping="NoWrap" VerticalAlignment="Center" Padding="2 0" Text="Remain" Visibility="{Binding Path=RemainVisibility}"/>
                    </StackPanel>
                    <ComboBox Grid.Column="2" 
                              ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.ChosenUsers}"
                              SelectedItem="{Binding Path=AssignedTo}"
                              DisplayMemberPath="Name"
                              IsEditable="True" IsTextSearchEnabled="True">
                    </ComboBox>
                    <Grid.Style>
                        <Style>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeViewItem}}}" Value="False">
                                    <Setter Property="Grid.Visibility" Value="Collapsed" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Grid.Style>
                </Grid>

            </Grid>
        </Border>
    </HierarchicalDataTemplate>




    <HierarchicalDataTemplate 
            x:Key="WorkItemUserStoryTemplate"
            ItemsSource="{Binding Path=Children}"
            >
        <Border BorderThickness="1" BorderBrush="LightGray" CornerRadius="2" Margin="1" >
            <Border.Style>
                <Style>
                    <Setter Property="Border.Background" >
                        <Setter.Value>
                            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                <GradientStop Color="White" Offset="0.0" />
                                <GradientStop Color="#eeeecc" Offset="0.5" />
                                <GradientStop Color="#ccccaa" Offset="1.0" />
                            </LinearGradientBrush>
                        </Setter.Value>
                    </Setter>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeViewItem}}}" Value="True">
                            <Setter Property="Border.Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding IsInParentIteration}" Value="False">
                            <Setter Property="Border.Background" Value="#ffffff" />
                            <Setter Property="TextBlock.Foreground" Value="#aaaaaa" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding IsClosed}" Value="True">
                            <Setter Property="TextBlock.Foreground" Value="#aaaaaa" />
                            <Setter Property="Border.Background" >
                                <Setter.Value>
                                    <ImageBrush ImageSource="pack://application:,,,/Pictures/closed-item.png" Stretch="Fill" />
                                </Setter.Value>
                            </Setter>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Border.Style>

            <Grid TextBlock.FontFamily="Corbel" TextBlock.FontSize="10" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>


                <TextBlock Grid.Row="0" Grid.ColumnSpan="2" TextWrapping="NoWrap" FontSize="14" FontWeight="800" Padding="2 0" Text="{Binding Title}"/>
                <Image Grid.Row="0" Grid.RowSpan="4" VerticalAlignment="Top" HorizontalAlignment="Right" Source="{Binding Path=AssignedTo.Image}"  Width="32" Height="32" Stretch="UniformToFill" Margin="2 1"></Image>

                <TextBlock Grid.Row="1" TextWrapping="Wrap" Padding="2 0" Text="{Binding Description}">
                      <TextBlock.Style>
                        <Style>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeViewItem}}}" Value="False">
                                    <Setter Property="TextBlock.Visibility" Value="Collapsed" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                      </TextBlock.Style>
                </TextBlock>

                <Grid Grid.Row="2">
                    <TextBlock TextWrapping="NoWrap" Padding="2 0" Text="{Binding State}"/>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" >
                        <TextBlock TextWrapping="NoWrap" Padding="2 0" Text="{Binding Points,StringFormat=\{0\} points\,}" Visibility="{Binding Path=PointsVisibility}"/>
                        <TextBlock TextWrapping="NoWrap" Padding="2 0" Text="{Binding TotalHours,StringFormat=Total \{0\} hours\,}" Visibility="{Binding Path=HoursVisibility}"/>
                        <TextBlock TextWrapping="NoWrap" Padding="2 0" Text="{Binding TotalRemain,StringFormat=\{0\} remain}" Visibility="{Binding Path=RemainVisibility}"/>
                    </StackPanel>
                    <Grid.Style>
                        <Style>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeViewItem}}}" Value="True">
                                    <Setter Property="Grid.Visibility" Value="Collapsed" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Grid.Style>
                </Grid>

                <Grid Grid.Row="3">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="2*" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <ComboBox Grid.Column="0"
                                  ItemsSource="{Binding Path=States}"
                                  Text="{Binding Path=State}" >
                    </ComboBox>
                    <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Center">
                        <extToolkit:DoubleUpDown  Width="40" HorizontalContentAlignment="Right" Text="{Binding Path=Points}" Minimum="0" FormatString="{Binding Path=PointsFormat}" Visibility="{Binding Path=PointsVisibility}"/>
                        <TextBlock TextWrapping="NoWrap" VerticalAlignment="Center" Padding="2 0" Text="Points" Visibility="{Binding Path=PointsVisibility}"/>
                    </StackPanel>
                    <ComboBox Grid.Column="2"
                              ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.ChosenUsers}"
                              SelectedItem="{Binding Path=AssignedTo}"
                              DisplayMemberPath="Name"
                              IsEditable="True" IsTextSearchEnabled="True">
                    </ComboBox>
                    <Grid.Style>
                        <Style>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeViewItem}}}" Value="False">
                                    <Setter Property="Grid.Visibility" Value="Collapsed" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Grid.Style>
                </Grid>

            </Grid>
        </Border>
    </HierarchicalDataTemplate>





    <HierarchicalDataTemplate 
            x:Key="WorkItemBugTemplate"
            ItemsSource="{Binding Path=Children}"
            >
        <Border BorderThickness="1" BorderBrush="LightGray" CornerRadius="2" Margin="1" >
            <Border.Style>
                <Style>
                    <Setter Property="Border.Background" >
                        <Setter.Value>
                            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                <GradientStop Color="White" Offset="0.0" />
                                <GradientStop Color="#eecccc" Offset="0.5" />
                                <GradientStop Color="#ccaaaa" Offset="1.0" />
                            </LinearGradientBrush>
                        </Setter.Value>
                    </Setter>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeViewItem}}}" Value="True">
                            <Setter Property="Border.Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding IsInParentIteration}" Value="False">
                            <Setter Property="Border.Background" Value="#ffffff" />
                            <Setter Property="TextBlock.Foreground" Value="#aaaaaa" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding IsClosed}" Value="True">
                            <Setter Property="TextBlock.Foreground" Value="#aaaaaa" />
                            <Setter Property="Border.Background" >
                                <Setter.Value>
                                    <ImageBrush ImageSource="pack://application:,,,/Pictures/closed-item.png" Stretch="Fill" />
                                </Setter.Value>
                            </Setter>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Border.Style>

            <Grid TextBlock.FontFamily="Corbel" TextBlock.FontSize="10" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>


                <TextBlock Grid.Row="0" Grid.ColumnSpan="2" TextWrapping="NoWrap" FontSize="14" FontWeight="800" Padding="2 0" Text="{Binding Title}"/>
                <Image Grid.Row="0" Grid.RowSpan="4" VerticalAlignment="Top" HorizontalAlignment="Right" Source="{Binding Path=AssignedTo.Image}"  Width="32" Height="32" Stretch="UniformToFill" Margin="2 1"></Image>

                <TextBlock Grid.Row="1" TextWrapping="Wrap" Padding="2 0" Text="{Binding Description}">
                      <TextBlock.Style>
                        <Style>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeViewItem}}}" Value="False">
                                    <Setter Property="TextBlock.Visibility" Value="Collapsed" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                      </TextBlock.Style>
                </TextBlock>

                <Grid Grid.Row="2">
                    <TextBlock TextWrapping="NoWrap" Padding="2 0" Text="{Binding State}"/>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" >
                        <TextBlock TextWrapping="NoWrap" Padding="2 0" Text="{Binding TotalHours,StringFormat=\{0\} Hours\,}" Visibility="{Binding Path=HoursVisibility}"/>
                        <TextBlock TextWrapping="NoWrap" Padding="2 0" Text="{Binding TotalRemain,StringFormat=\{0\} Remain}" Visibility="{Binding Path=RemainVisibility}"/>
                    </StackPanel>
                    <Grid.Style>
                        <Style>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeViewItem}}}" Value="True">
                                    <Setter Property="Grid.Visibility" Value="Collapsed" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Grid.Style>
                </Grid>

                <Grid Grid.Row="3">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="2*" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <ComboBox Grid.Column="0"
                                  ItemsSource="{Binding Path=States}"
                                  Text="{Binding Path=State}" >
                    </ComboBox>
                    <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Center">
                        <extToolkit:DoubleUpDown  Width="40" HorizontalContentAlignment="Right" Text="{Binding Path=Hours}" Minimum="0" FormatString="{Binding Path=HoursFormat}" Visibility="{Binding Path=HoursVisibility}"/>
                        <TextBlock TextWrapping="NoWrap" Padding="2 0" VerticalAlignment="Center" Text="Hours, " Visibility="{Binding Path=HoursVisibility}"/>
                        <extToolkit:DoubleUpDown  Width="40" HorizontalContentAlignment="Right" Text="{Binding Path=Remain}" Minimum="0" FormatString="{Binding Path=RemainFormat}" Visibility="{Binding Path=RemainVisibility}"/>
                        <TextBlock TextWrapping="NoWrap" VerticalAlignment="Center" Padding="2 0" Text="Remain" Visibility="{Binding Path=RemainVisibility}"/>
                    </StackPanel>
                    <ComboBox Grid.Column="2"
                              ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.ChosenUsers}"
                              SelectedItem="{Binding Path=AssignedTo}"
                              DisplayMemberPath="Name"
                              IsEditable="True" IsTextSearchEnabled="True">
                    </ComboBox>
                    <Grid.Style>
                        <Style>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeViewItem}}}" Value="False">
                                    <Setter Property="Grid.Visibility" Value="Collapsed" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Grid.Style>
                </Grid>

            </Grid>
        </Border>
    </HierarchicalDataTemplate>


</ResourceDictionary>